home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
626-637
/
disk_629
/
rexxrmf
/
rexxrmf.lzh
/
test.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1992-03-14
|
7KB
|
204 lines
/* This example illustrates how to use 'low level' AVL-tree functions */
/* for simple indexing, nothing meaningful is done here. */
/* DO NOT inter-mix the add_key(), delete_key() functions with the
DELETE_RMF_RECORD, READ_RMF_RECORD and WRITE_RMF_RECORD functions.
You are just asking for trouble if you do.
'low level' functions which simply return information, but do not
modify the tree, can safely be inter-mixed with the ...RMF_RECORD
functions.
Though nothing useful is done in this example, remember that the
'low level' functions do not perform any I/O to the data file.
Therefore if you are just looking for the existence of a key,
it is much faster to simply do a "find_key()", instead of a
READ_RMF_RECORD().
*/
x = addlib("RexxRMF.library",0,-30,0)
x = addlib("rexxsupport.library",0,-30,0)
ix = open_rmf() /* no data file or index file will be created */
/* simply using search/sort capabilities of AVL */
/* cannot save the index, cuz we did not open it with a name */
if ix = '0000 0000'x then exit
p = showlist('P') /* build list of names, message port names */
do forever /* insert names from showlist() into tree */
/* insertion occurs such that the names */
/* are sorted in alphabetical order */
if p = '' then leave /* when list is exhausted leave */
parse var p aportname p /* parse out a name */
treenode = add_key(ix,0,aportname,0) /* add portname to the tree */
end
/* ---------------------------------- */
/* Now print the contents of the tree */
/* ---------------------------------- */
i = 1
do forever
treenode = find_pos(ix,0,i) /* find by position (ie. in sorted order) */
if treenode = '0000 0000'x then leave
say " Node " i '=' key_value(treenode) /* print value of key */
i = i + 1
end
/* ---------------------------------- */
/* adding some more keys into tree */
/* ---------------------------------- */
do i = 1 to 8
z = add_key(ix,0,"Ron_nie",0) /* add a key into the tree */
/* create multiple occurences */
end
z = add_key(ix,0,"RHONDA",0) /* create multiple occurences */
z = add_key(ix,0,"RHONDA",0)
z = add_key(ix,0,"RHONDA",0)
z = add_key(ix,0,"RONNIE",0) /* create multiple occurences */
z = add_key(ix,0,"RONNIE",0)
z = add_key(ix,0,"RONNIE",0)
/* ---------------------------------- */
say ""
say " Looking for RHONDA ... "
akey = find_key(ix,0,"RHONDA",1) /* find first occurence of RHONDA */
do while akey ~= '0000 0000'x /* while akey not = null */
say "Found KEY:" key_value(akey) /* value of the key */
say "Occurence:" key_occur(akey) /* which occurence is it */
say "Position :" node_pos(akey) /* relative position, sorted order */
/* find_next() finds the NEXT node with same key value that was */
/* specified in the most recent find_key() call. */
akey = find_next(ix,0) /* this find_next() will find the */
/* next occurence of RHONDA */
/* when no more occurences, then */
/* akey will be equal to null */
/* akey = null will terminate the */
/* loop */
end
say " Done Looking for RHONDA." /* should be 3 occurences of RHONDA */
say ""
say ""
/* -------------------------------------------------- */
/* the difference between locate_key() and find_key() */
/* find_key() wants an exact match, both on the key */
/* value and the occurence. */
/* locate_key() will matche partial key strings */
/* -------------------------------------------------- */
say ""
say " Looking for anything beginning with R ... "
string = "R"
akey = locate_key(ix,0,string,1) /* will locate any key beginning with "R" */
do until akey = '0000 0000'x
if akey ~= '0000 0000'x then
say "LOCATED KEY" key_value(akey) "occurence" key_occur(akey) "position" node_pos(akey)
akey = locate_next(ix,0)
end
say " Done Looking for things beginning with R. "
say ""
say ""
/* ---------------------------------- */
/* gonna delete 2 of RHONDA's keys */
/* ---------------------------------- */
z = delete_key(ix,0,"RHONDA",1) /* delete first occurence of RHONDA */
/* will cause mulitples occur number */
/* to be adjusted accordingly */
z = delete_key(ix,0,"RHONDA",1) /* what was occurence #2 is now occur */
/* occur #1 */
/* ---------------------------------------------------- */
/* should only be 1 occurence of RHONDA in the tree now */
/* ---------------------------------------------------- */
say ""
say " Looking for RHONDA ... (again) "
akey = find_key(ix,0,"RHONDA",1) /* find first occurence of RHONDA */
do while akey ~= '0000 0000'x /* while akey not = null */
say "Found KEY:" key_value(akey) /* value of the key */
say "Occurence:" key_occur(akey) /* which occurence is it */
say "Position :" node_pos(akey) /* relative position, sorted order */
/* find_next() finds the NEXT node with same key value that was */
/* specified in the most recent find_key() call. */
akey = find_next(ix,0) /* this find_next() will find the */
/* next occurence of RHONDA */
/* when no more occurences, then */
/* akey will be equal to null */
/* akey = null will terminate the */
/* loop */
end
say " Done Looking for RHONDA." /* should be 1 occurence of RHONDA */
say ""
say ""
/* ---------------------------------- */
/* print the entire tree */
/* ---------------------------------- */
i = 1
do forever
treenode = find_pos(ix,0,i) /* find by position (ie. in sorted order) */
if treenode = '0000 0000'x then leave
say " Node " i '=' key_value(treenode) /* print value of key */
i = i + 1
end
x = close_rmf(ix,0) /* close index, releasing mem used */
exit